{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ae583f5e-51ab-4cd6-a9f0-89a060d59cea",
   "metadata": {},
   "outputs": [],
   "source": [
    "from python_a2a.client import A2AClient\n",
    "\n",
    "agent_url = \"http://localhost:7002\"\n",
    "# 创建客户端，指向你运行的代理服务地址\n",
    "client = A2AClient(agent_url)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "90729831",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Error: Failed to communicate with agent at http://localhost:7002/tasks/send. Tried multiple endpoint variations.\n"
     ]
    }
   ],
   "source": [
    "response = client.ask(\"我打算去东京旅游三天，请帮我生成一份详细攻略\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "66f00167",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "从1加到200的结果是20100。\n"
     ]
    }
   ],
   "source": [
    "response = client.ask(\"从1加到200等于多少\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "6d1a8ea0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "答案是320。您的计算3*100+20等于320。\n"
     ]
    }
   ],
   "source": [
    "response = client.ask(\"3*100+20等于多少\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c83b5ebf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "现在是2025年6月28日星期六，时间为晚上18点41分。\n"
     ]
    }
   ],
   "source": [
    "response = client.ask(\"现在几点了\")\n",
    "print(response)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6f770d09",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "今天的日期是2025年6月28日，是星期六。昨天是2025年6月27日，而明天将会是2025年6月29日。\n"
     ]
    }
   ],
   "source": [
    "response = client.ask(\"今天是几号？昨天什么日期？明天什么日期？\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "08d965c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您现在在新加坡，当地的时间是2025年6月28日的19:18。至于悉尼的时间，我很抱歉，我需要一些时间来查询。请稍等。\n"
     ]
    }
   ],
   "source": [
    "response = client.ask(\"我现在在新加坡，现在几点了？悉尼现在是什么时间？\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "cb89196b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "东京现在的天气是阴天和多云，气温为28.69°C，但体感温度稍高，约为29.73°C。请根据天气状况适当调整穿着，保持舒适。\n"
     ]
    }
   ],
   "source": [
    "response = client.ask(\"帮我查东京的温度\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c012bb7f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "东京现在的天气是阴，多云，温度为28.86°C，体感温度为31.9°C，这样的天气还是非常适合出游的。您可以考虑参观以下几个景点：\n",
      "1. 上野公园：这是东京最大的公园之一，现在天气凉爽，适合在公园里散步，欣赏美景。\n",
      "2. 浅草寺和雷门：这是东京最古老的寺庙，阴天的天气更能突显寺庙的历史沉淀感。\n",
      "3. 晴空塔：您可以去这座东京最高的塔上欣赏东京的全景，如果天气转晴，透明的塔身会显得非常美丽。\n",
      "4. 东京塔和墨田区塔：这两座塔都是东京的地标，云层较多的天气下可以欣赏到不同的风景。\n",
      "\n",
      "希望这些建议对您有所帮助并享受您在东京的旅程！\n"
     ]
    }
   ],
   "source": [
    "# 测试多工具调用\n",
    "response = client.ask(\"东京现在的天气怎么样？根据天气给我推荐几个适合游览的景点\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "multi-tool-test",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7月份有31天。关于你7月1日去东京旅游的天气情况，我需要额外查询一下，请稍等。\n"
     ]
    }
   ],
   "source": [
    "# 测试多工具组合调用\n",
    "response = client.ask(\"请先计算一下7月份有多少天，然后告诉我如果我7月1日去东京旅游，当地天气如何？\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "complex-multi-tool-test",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 测试复杂多工具组合调用\n",
    "response = client.ask(\"我计划下周去巴黎旅游，并且告诉我当地的天气情况，然后推荐各自的热门景点和美食\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "multi-turn-test",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第一轮对话：\n",
      "非常抱歉，我现在暂时无法获取到北京的著名景点信息。但是，北京作为中国的首都，有很多著名的景点，比如故宫博物院、天坛公园、颐和园等。如果您需要更详细的信息，可能需要稍后再试。对此造成的不便，我深感抱歉。\n",
      "第二轮对话：\n",
      "对于带孩子的家庭来说，以下是几个北京的适合带孩子游玩的景点：\n",
      "\n",
      "1. 北京动物园：拥有各种各样的动物，包括大熊猫。有海洋馆可以参观，适合全家出行。\n",
      "\n",
      "2. 科技馆：集科技、教育、娱乐为一体的知识性强的地方，动手能力强，适合孩子来玩。\n",
      "\n",
      "3. 国家博物馆：藏品丰富，可以让小孩了解更多中国历史文化。\n",
      "\n",
      "4. 星空剧场和国家大剧院：可以看到各种演出和活动，增加孩子的艺术格局。\n",
      "\n",
      "5. 奥体中心：参观鸟巢，水立方等奥运场馆。\n",
      "\n",
      "6. 颐和园、天坛等公园：可以领略北京的历史文化，同时公园里的空气新鲜，环境宜人，适合全家出行。\n",
      "\n",
      "以上的景点中同时也包含了教育以及娱乐元素，是家庭旅行的不错选择。希望这些建议可以帮助到您！\n",
      "第三轮对话：\n",
      "当然，根据我查询到的信息，北京的当前天气是阴天，多云，温度是28.93°C，人体感觉的温度大约是31.07°C。这样的气候条件下，您去户外的地方应该会感觉舒服。但请记住，出门前要根据天气变化适当添加或减少衣物。\n"
     ]
    }
   ],
   "source": [
    "# 测试多轮对话\n",
    "print(\"第一轮对话：\")\n",
    "response1 = client.ask(\"北京有哪些著名的景点？\")\n",
    "print(response1)\n",
    "\n",
    "print(\"第二轮对话：\")\n",
    "response2 = client.ask(\"这些景点中哪些适合带孩子去？\")\n",
    "print(response2)\n",
    "\n",
    "print(\"第三轮对话：\")\n",
    "response3 = client.ask(\"现在的天气适合去这些地方吗？\")\n",
    "print(response3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "multi-tool-turn-test",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 测试多工具调用和多轮对话结合\n",
    "print(\"第一轮对话：\")\n",
    "response1 = client.ask(\"上海现在的天气怎么样？\")\n",
    "print(response1)\n",
    "\n",
    "print(\"第二轮对话：\")\n",
    "response2 = client.ask(\"根据这个天气，推荐几个适合游览的景点\")\n",
    "print(response2)\n",
    "\n",
    "print(\"第三轮对话：\")\n",
    "response3 = client.ask(\"这些景点附近有什么好吃的餐厅？\")\n",
    "print(response3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ac28324d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "深圳现在的天气状况是阴天，多云，当前温度为31.64°C，但体感温度达到了38.64°C，请注意防晒和补水，保持舒适哦。\n"
     ]
    }
   ],
   "source": [
    "response = client.ask(\"深圳现在多少度？\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "403fc4fe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "根据我获取的信息，深圳现在的天气是阴天，多云，当前的实际温度是31.73°C，但是体感温度达到了38.73°C，这意味着天气会感觉非常热。所以，如果你计划出游，我建议你带上适量的防晒品以防曝晒，同时也准备一些清凉的饮料以保持身体水分。因为天气可能有点热，所以建议你尽量避免在烈日当空的中午时段活动，而是选择在早晚比较凉快的时候出行。这样一来，你就可以在深圳愉快地旅行了。祝你旅途愉快！\n"
     ]
    }
   ],
   "source": [
    "response = client.ask(\"根据深圳现在的天气，给我一些旅行建议\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c7a58c33",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当然可以。以下是一些运动建议：\n",
      "\n",
      "1. **定期运动**：设定一个每周运动的次数目标，并确保每次运动的时间至少为30分钟。\n",
      "\n",
      "2. **多样化**：尝试多种类型的运动以保持新鲜感并使全身各部位都得到锻炼。例如，你可以选择跑步、游泳、骑自行车、瑜伽等不同的运动。\n",
      "\n",
      "3. **适度的强度**：努力达到一个可以说话但不能唱歌的呼吸频率，可以保证运动强度适宜。\n",
      "\n",
      "4. **深度拉伸**：在每次运动前后都要进行充分的拉伸。这可以帮助预防运动伤害并提高身体的柔韧性。\n",
      "\n",
      "5. **保持水分和营养**：在运动期间和运动后补充足够的水分和营养，以保持身体的最佳状态。\n",
      "\n",
      "6. **休息日**：每周至少安排一到两天的休息日，让身体有时间恢复和修复。\n",
      "\n",
      "7. **在医生或健康专家的指导下进行运动**：如果你有任何健康问题，都应在医生或健康专家的指导下进行运动。\n",
      "\n",
      "希望以上这些建议可以帮到你，健康和快乐地运动！\n"
     ]
    }
   ],
   "source": [
    "response = client.ask(\"给我一些运动建议\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a43d8b4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "复旦大学的经纬度坐标是东经121.503560,北纬31.296335。这是复旦大学邯郸校区在地图上的准确位置。如果您需要前往那里，可以从复旦大学地铁站2号口出发，步行约390米即可到达。\n"
     ]
    }
   ],
   "source": [
    "# test amap_geocode\n",
    "response = client.ask(\"告诉我复旦大学的经纬度坐标\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "082bf6cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "在复旦大学周围，我为您筛选出了以下一些咖啡店推荐：\n",
      "\n",
      "1. [瑞幸咖啡(复旦大学江湾光华MALL店)](https://www.amap.com/place/B0J1VC3YIB)，位于国权北路1380号复旦大学江湾光华餐厅一层大堂，距离约65米。\n",
      "\n",
      "2. [熙贤咖啡](https://www.amap.com/place/B0FFIGBV5H)，位置在国权路525号副楼(复旦大学地铁站2号口步行490米)，距离约252米。\n",
      "\n",
      "3. [Manner Coffee(复华科技大楼店)](https://www.amap.com/place/B0J2P5AZNO)，地址是邯郸路220号复华科技大楼F1层，距离约280米。\n",
      "\n",
      "4. [瑞幸咖啡(国权路店)](https://www.amap.com/place/B0I3KD79IN)，位于国权路525号复华科技大楼底商，距离约284米。\n",
      "\n",
      "5. [SilverFlow银流咖啡&贝果(复华科技大楼店)](https://www.amap.com/place/B0JDZ5CTK2)，地址是国权路525号复华科技大楼大堂，距离约294米。\n",
      "\n",
      "您可以点击名称查看他们的具体位置和更多信息，享受您的咖啡时光吧！\n"
     ]
    }
   ],
   "source": [
    "# test amap_geocode, amap_place_around, completion\n",
    "response = client.ask(\"给我推荐一下复旦大学周围的咖啡店\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5290b187",
   "metadata": {},
   "source": [
    "在复旦大学周围，我为您筛选出了以下一些咖啡店推荐：\n",
    "\n",
    "1. [瑞幸咖啡(复旦大学江湾光华MALL店)](https://www.amap.com/place/B0J1VC3YIB)，位于国权北路1380号复旦大学江湾光华餐厅一层大堂，距离约65米。\n",
    "\n",
    "2. [熙贤咖啡](https://www.amap.com/place/B0FFIGBV5H)，位置在国权路525号副楼(复旦大学地铁站2号口步行490米)，距离约252米。\n",
    "\n",
    "3. [Manner Coffee(复华科技大楼店)](https://www.amap.com/place/B0J2P5AZNO)，地址是邯郸路220号复华科技大楼F1层，距离约280米。\n",
    "\n",
    "4. [瑞幸咖啡(国权路店)](https://www.amap.com/place/B0I3KD79IN)，位于国权路525号复华科技大楼底商，距离约284米。\n",
    "\n",
    "5. [SilverFlow银流咖啡&贝果(复华科技大楼店)](https://www.amap.com/place/B0JDZ5CTK2)，地址是国权路525号复华科技大楼大堂，距离约294米。\n",
    "\n",
    "您可以点击名称查看他们的具体位置和更多信息，享受您的咖啡时光吧！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d0a18f96",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "以下是我为您找到的上海交通大学闵行校区周围的几家咖啡店供您参考：\n",
      "\n",
      "1. [瑞幸咖啡(上海交大闵行校区店)](https://www.amap.com/place/B0FFM1DBCV)：位于东川路800上海交通大学闵行校区第三餐饮大楼，距离学校约395米。\n",
      "   \n",
      "2. [E+咖啡厅](https://www.amap.com/place/B0FFL8W6RD)：位于上海交通大学电信学院2.3号楼之间，距离学校约414米。\n",
      "   \n",
      "3. [左岸咖啡(国家电投店)](https://www.amap.com/place/B0KA5Y9NT7)：位于南洋北路与学森路交叉口东北120米，距离学校约416米。\n",
      "   \n",
      "4. [校园咖啡(龙坡路)](https://www.amap.com/place/B00155M6IV)：位于东川路800上海交通大学闵行校区，距离学校约433米。\n",
      "   \n",
      "5. [暴走的咖啡豆(交通大学店)](https://www.amap.com/place/B0J0BUUBN2)：位于东川路800号(人文学院二楼连廊)，距离学校约496米。\n",
      "\n",
      "希望以上信息对您有所帮助。\n"
     ]
    }
   ],
   "source": [
    "response = client.ask(\"给我推荐一下上海交通大学周围的咖啡店\")\n",
    "print(response)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "476b7554",
   "metadata": {},
   "source": [
    "以下是我为您找到的上海交通大学闵行校区周围的几家咖啡店供您参考：\n",
    "\n",
    "1. [瑞幸咖啡(上海交大闵行校区店)](https://www.amap.com/place/B0FFM1DBCV)：位于东川路800上海交通大学闵行校区第三餐饮大楼，距离学校约395米。\n",
    "   \n",
    "2. [E+咖啡厅](https://www.amap.com/place/B0FFL8W6RD)：位于上海交通大学电信学院2.3号楼之间，距离学校约414米。\n",
    "   \n",
    "3. [左岸咖啡(国家电投店)](https://www.amap.com/place/B0KA5Y9NT7)：位于南洋北路与学森路交叉口东北120米，距离学校约416米。\n",
    "   \n",
    "4. [校园咖啡(龙坡路)](https://www.amap.com/place/B00155M6IV)：位于东川路800上海交通大学闵行校区，距离学校约433米。\n",
    "   \n",
    "5. [暴走的咖啡豆(交通大学店)](https://www.amap.com/place/B0J0BUUBN2)：位于东川路800号(人文学院二楼连廊)，距离学校约496米。\n",
    "\n",
    "希望以上信息对您有所帮助。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "9daf0967",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "据最新天气预报，以下是接下来几天苏州（姑苏区）的天气情况：\n",
      "\n",
      "- 2025-07-02（周三）：白天晴，夜间多云，最高温度36℃，最低温度27℃，风向东南，风速1-3级。\n",
      "- 2025-07-03（周四）：白天多云，夜间多云，最高温度36℃，最低温度27℃，风向东南，风速1-3级。\n",
      "- 2025-07-04（周五）：白天多云，夜间多云，最高温度37℃，最低温度28℃，风向东南，风速1-3级。\n",
      "- 2025-07-05（周六）：白天多云，夜间晴，最高温度38℃，最低温度28℃，风向东南，风速1-3级。\n",
      "\n",
      "请根据实际情况做好防晒和防暑工作。\n"
     ]
    }
   ],
   "source": [
    "response = client.ask(\"我需要苏州的天气预报\")\n",
    "print(response)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "a2a",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
